package com.xzj.admin.resource.sync.controller;

import com.xzj.admin.resource.sync.domain.dict.DictItemTree;
import com.xzj.admin.resource.sync.domain.vo.SelectPortOption;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import com.xzj.common.datasource.domain.PageReq;
import cn.hutool.core.util.ObjectUtil;
import com.xzj.common.datasource.domain.PageResp;
import com.xzj.admin.resource.sync.domain.entity.ResScriptManage;
import com.xzj.admin.resource.sync.service.ResScriptManageService;

import java.util.List;
import java.util.Map;

/**
 * @program: xzj-admin
 * @ClassName: ResScriptManageController
 * @description: 资源处理脚本管理;(res_script_manage)表控制层
 * @author: XiaZunJun
 * @create: 2024-10-24
 */
@Tag(name = "资源处理脚本管理对象功能接口")
@RestController
@RequestMapping("/resScriptManage")
public class ResScriptManageController{
    @Resource
    private ResScriptManageService resScriptManageService;

    /**
     * 通过ID查询单条数据
     *
     * @param scriptId 主键
     * @return 实例对象
     */
    @Operation(summary = "通过ID查询单条数据")
    @GetMapping("/queryById/{scriptId}")
    public ResScriptManage queryById(@PathVariable(name = "scriptId") String scriptId){
        return resScriptManageService.queryById(scriptId);
    }

    /**
     * 分页查询
     *
     * @param pageReq 分页筛选条件对象
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @PostMapping("/pageQuery")
    public PageResp<ResScriptManage> pageQuery(@RequestBody PageReq<ResScriptManage> pageReq){
        return resScriptManageService.pageQuery(pageReq);
    }

    /**
     * 根据云类型查询私有和所有公共脚本
     *
     * @return 查询结果
     */
    @Operation(summary = "根据云类型查询私有和所有公共脚本")
    @GetMapping("/queryAllByCloud/{cloudOption}")
    public Map<String, List<SelectPortOption>> queryAllByCloud(@PathVariable(name = "cloudOption") String cloudOption){
        return resScriptManageService.queryAllByCloud(cloudOption);
    }

    /**
     * 新增数据
     *
     * @param resScriptManage 实例对象
     * @return 实例对象
     */
    @Operation(summary ="新增Or更新数据")
    @PostMapping("/addOrUpdate")
    public ResScriptManage addOrUpdate(@RequestBody ResScriptManage resScriptManage){
        if(ObjectUtil.isNotEmpty(resScriptManage.getScriptId())){
            resScriptManageService.update(resScriptManage);
        }else{
            resScriptManageService.insert(resScriptManage);
        }
        return resScriptManage;
    }

    /**
     * 通过主键删除数据
     *
     * @param scriptId 主键
     * @return 是否成功
     */
    @Operation(summary ="通过主键删除数据")
    @GetMapping("/deleteById/{scriptId}")
    public boolean deleteById(@PathVariable(name = "scriptId") String scriptId){
        return resScriptManageService.deleteById(scriptId);
    }

    @Operation(summary = "左侧树")
    @GetMapping("/getDictTree")
    public List<DictItemTree> getDictTree(){
        return resScriptManageService.getDictTree();
    }

    @Operation(summary = "云类型级联")
    @GetMapping("/cloudTypeCascade")
    public List<DictItemTree> cloudTypeCascade(){
        return resScriptManageService.cloudTypeCascade();
    }

}